<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <!--引入vue和axios-->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!--引入全局基础变量-->
    <script src="js/common.js"></script>
</head>
<body>
    <div id="app"></div>
</body>
    <script type="text/javascript">
        new Vue({
            el: "#app",
            data:{},
            methods:{
                
            },
            
            mounted(){
                //http://bugtracker.itsource.cn/callback.html?code=071EIJkl25FKC94uf4ll2tViol2EIJkc&state=1
                //页面只要加载,就获取code,发送请求给后端
                var url = location.href;
                //拿到?位置,从?后面一位开始截取
                //code=071EIJkl25FKC94uf4ll2tViol2EIJkc&state=1
                //var path = url.substring(url.indexOf("?")+1)
                
                //直接使用工具类 ,封装在 commom.js 里面
                var jsonObj = parseUrlParams2Obj(url);
                //获取授权码
                var code = jsonObj.code;
                
                this.$http.get("/login/weChat/"+code)
                    .then(res=>{
                        if(res.data.success){
                            //1.把key(token)和user,存入localStorage
                            //获取token
                            var token = res.data.resultObj.token;
                            //用户信息
                            var logininfo = res.data.resultObj.logininfo;
                            localStorage.setItem("token",token);
                            //JSON.stringify(logininfo)把json对象转成json字符串
                            localStorage.setItem("logininfo",JSON.stringify(logininfo));

                            //2.跳转到首页
                            location.href="index.html";
                        }else{  //没有绑定
                            //String param = "?accessToken="+access_token+"&openId="+openid;
                            var param = res.data.resultObj;
                            location.href="binder.html"+param;
                        }
                        
                    }).catch(res=>{
                        
                })
            },
        })
        
    </script>
</html>